﻿using ESRI.ArcGIS.Client.Geometry;
using QDP.Platform.ObjService;
using QDP.Platform.Silverlight.Tools;

namespace Apps.Maps
{
    public static class GSLayerExt
    {
        public static Envelope GetDefaultEnvelope(this ServiceLayer thiz)
        {
            var configs = ParmsExpressionHelper.ToDictionary(thiz.ParmsExpression);

            if (configs.ContainsKey("XMin")
                && configs.ContainsKey("XMax")
                && configs.ContainsKey("YMin")
                && configs.ContainsKey("YMax"))
            {
                double xmin, xmax, ymin, ymax;
                if (double.TryParse(configs["XMin"], out xmin)
                    && double.TryParse(configs["XMax"], out xmax)
                    && double.TryParse(configs["YMin"], out ymin)
                    && double.TryParse(configs["YMax"], out ymax))

                    return new Envelope(xmin,ymin,xmax,ymax);
                else
                    return null;
            }
            else
            {
                return null;
            }
        }
    }
}